<template>
  <!-- 通用查看签到弹框 -->
  <base-modal
    :footer="null"
    title="签到人员"
    :closable="true"
    @cancel="handleClose"
    :visible="visible"
    width="900px"
  >
    <b-table
      bordered
      ref="table"
      :columns="column"
      :request="loadData"
      :show-page="false"
    >
      <span
        slot="serial"
        slot-scope="text, record, index"
      >{{ index + 1 }}</span>
    </b-table>
  </base-modal>
</template>

<script>
import { meetingEmployee } from '@/api/office/conference'
import training from '@/api/design/training'
import BaseModal from '@/components/BaseModal'
import { STable } from '@/components'
import { recordSignList } from '@/api/safetySupervision/safteyClosureRecord'

const column = [
  {
    title: '序号',
    dataIndex: 'serial',
    width: '15%',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '签到地点',
    dataIndex: 'signAddress'
  },
  {
    title: '签到公司',
    dataIndex: 'signCompany'
  },
  {
    title: '签到人',
    dataIndex: 'signUser'
  },
  {
    title: '签到时间',
    dataIndex: 'signDate'
  }
]

export default {
  components: {
    BaseModal,
    STable
  },
  props: {
    id: {
      type: String,
      default: ''
    },
    visible: {
      type: Boolean,
      default: false
    },
    isNew: {
      type: Boolean,
      default: false
    }
  },
  data() {
    this.column = column
    return {
      loadData: async (q) => {
        let res = await recordSignList(Object.assign({}, q, { id: this.id }))
        if (res.code === 200) {
          if (res.data instanceof Array) {
            return res
          }
        }
        return { code: 200, data: [] }
      },
      timer: null
    }
  },
  created() {
  },
  methods: {
    handleClose() {
      this.$emit('confirm')
    }
  },
  watch: {
    visible(v) {
      if (v) {
        this.$nextTick(() => {
          this.$refs.table.refresh()
          this.timer = setInterval(this.$refs.table.refresh, 2000)
        })
      } else {
        clearInterval(this.timer)
        if (this.$refs.table) {
          this.$refs.table.localDataSource = []
        }
      }
    }
  }
}
</script>

